#ifndef MAINOPTIONS_H
#define MAINOPTIONS_H

/* Copyright (C) 2011 Riccardo Marson

   This file is part of OpenPool, an open-source game of pool. 

   Permission is hereby granted, free of charge, to any person obtaining a
   copy of this software and associated documentation files (the "Software"),
   to deal in the Software without restriction, including without limitation
   the rights to use, copy, modify, merge, publish, distribute, sublicense,
   and/or sell copies of the Software, and to permit persons to whom the
   Software is furnished to do so, subject to the following conditions:

   The above copyright notice and this permission notice shall be included
   in all copies or substantial portions of the Software.

   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
   RICCARDO MARSON BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
   AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
   CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

  See Readme.rtf for further information.
  
*/

#include <string>
#include <utility>
#include <map>

#include "as_addon/scriptdictionary.h"

#include "interfaces.h"
#include "glengine.h"
#include "logic.h"

class CCoreApplication;

// This class as a full script interface.

// general configuration options
class CConfigOptions
{
public:

    CConfigOptions();
    ~CConfigOptions();

    // TODO: find a way to save a script
    void saveConfigOptions();

    //Options are exposed for ease of use.
    int windowWidth;
    int windowHeight;
    bool castShadows;
    bool playMusic;
    bool playSoundEffects;
    float gravity;
    float airDensity;
    float frictionCoefficient;
    float simTimeStep;
    bool physicsDebugModeOn;

    //Advanced options, not configurable through the QML GUI
    std::string logFileName;
    bool logDebugModeActive;

};

// This class provided an interface for the script World / Level loading routines
// All that the script engine needs to interact with the main window during level
// creation is boxed here instead of giving the script direct access to the
// application core.
class CLevelLoader
{
public:
	CLevelLoader(CCoreApplication* parent = NULL) {
		mParent = parent;
		refcount = 0;
	}
	~CLevelLoader() {}

	//------------------------------------------------------------
	// This class is reference-counted by the AS garbage collector
	int AddRef()
	{
		return ++refcount;
	}

	int Release()
	{
		if (--refcount == 0)
		{
			delete this;
			return 0;
		}
		else
			return refcount;
	}
	//------------------------------------------------------------

	void NewObject(CScriptDictionary* objTable);

	/*
	void newGLLight(string name, eLightType type, CVector3& position,
			CMaterial& properties);

	void newGLCamera(string name, CVector3& position, CVector3 lookAt,
				CVector3& up, float clipNear, float clipFar);

	void newPoolBall(string name, eBallID id, float radius,
			float mass, CVector3 &pos, CVector3 &vel, string modelName, CMaterial &mat);

	void newSocket(string name, eBallID id, float radius, CVector3& position);

	void newGLProp(string name, eObjectType type, string modelName, CMaterial &mat, float bbox,
			CVector3& pos, CVector3& dir);

	void newCollisionPlane(string name, float w, float h, CVector3& position, CVector3 &normal);
*/

private:

	void AddObject(CScriptDictionary* objTable, eObjectType type);
	void AddLight(CScriptDictionary* objTable);
	void AddCamera(CScriptDictionary* objTable);

	void AddCollisionShape(ObjectPtr obj, eCollisionShape csID, CScriptDictionary* objTable);

	CCoreApplication* mParent;

	int refcount;

};

#endif // MAINOPTIONS_H
